﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;
using proRFID_DiemDanh.Chung;

namespace proRFID_DiemDanh.LichDay
{
    public partial class ThemLichDay : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                Load_DDL_GiaoVien();
                Load_DDL_MonHoc();
                Load_DDL_Phong();
                Load_DDL_Lop();
            } 
        }
        protected void cmd_them_Click(object sender, ImageClickEventArgs e)
        {
            DataTable dt = new DataTable();
            dt = mdLichDay.sp_LichDay_Insert(txt_NgayDay.Text, Int16.Parse(ddl_BuoiHoc.SelectedValue), Int16.Parse(ddl_GiaoVien.SelectedValue), Int16.Parse(ddl_PhongHoc.SelectedValue), Int16.Parse(ddl_MonHoc.SelectedValue), Int16.Parse(ddl_Lop.SelectedValue));
            if (dt.Rows[0]["ErrCode"].ToString() == "0")
            {
                mdMain.OKCancelBox(this, dt.Rows[0]["ErrMsg"].ToString() + "\\nBạn có tiếp tục thêm dữ liệu không?", "../LichDay/LichDay.aspx");
                txt_NgayDay.Text = "";
                ddl_BuoiHoc.SelectedIndex = 0;
                ddl_GiaoVien.SelectedIndex = 0;
                ddl_Lop.SelectedIndex = 0;
                ddl_MonHoc.SelectedIndex = 0;
                ddl_PhongHoc.SelectedIndex = 0;
            }
            else if (dt.Rows[0]["ErrCode"].ToString() == "1")
            {
                mdMain.OKBox(this, dt.Rows[0]["ErrMsg"].ToString(), "../LichDay/LichDay.aspx");
            }
            else
            {
                mdMain.OKCancelBox(this, dt.Rows[0]["ErrMsg"].ToString(), "../LichDay/LichDay.aspx");
            }
        }
        void Load_DDL_GiaoVien()
        {
            DataTable dt = new DataTable();
            dt = mdLichDay.sp_GiaoVien_DDL(0);
            ddl_GiaoVien.DataSource = dt;
            ddl_GiaoVien.DataValueField = "MAGV";
            ddl_GiaoVien.DataTextField = "HOTENGV";
            ddl_GiaoVien.DataBind();
        }
        void Load_DDL_Phong()
        {
            DataTable dt = new DataTable();
            dt = mdLichDay.sp_PhongHoc_DDL();
            ddl_PhongHoc.DataSource = dt;
            ddl_PhongHoc.DataValueField = "MAPHONG";
            ddl_PhongHoc.DataTextField = "TENPHONG";
            ddl_PhongHoc.DataBind();
        }
        void Load_DDL_MonHoc()
        {
            DataTable dt = new DataTable();
            dt = mdLichDay.sp_MonHoc_DDL();
            ddl_MonHoc.DataSource = dt;
            ddl_MonHoc.DataValueField = "MAMH";
            ddl_MonHoc.DataTextField = "TENMH";
            ddl_MonHoc.DataBind();
        }
        void Load_DDL_Lop()
        {
            DataTable dt = new DataTable();
            dt = mdLichDay.sp_Lop_DDL();
            ddl_Lop.DataSource = dt;
            ddl_Lop.DataValueField= "MALOP";
            ddl_Lop.DataTextField = "TENLOP";
            ddl_Lop.DataBind();
        }

        protected void Imgcmd_ThemPhong_Click(object sender, ImageClickEventArgs e)
        {
            Response.Redirect("/PhongHoc/ThemPhong.aspx");
        }

        protected void Imgcmd_ThemMon_Click(object sender, ImageClickEventArgs e)
        {
            Response.Redirect("/MonHoc/ThemMonHoc.aspx");
        }

        protected void Imgcmd_ThemLop_Click(object sender, ImageClickEventArgs e)
        {
            Response.Redirect("/Lop/ThemLop.aspx");
        }

        
    }
}